package com.holdtime.jtt809dataservice.app;

import com.holdtime.jtt809dataservice.client.handler.SubordinatePlatformClientHandler;
import com.holdtime.jtt809dataservice.client.socket.TcpClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import protocol.jtt809.ProtocolJT809;

/**
 * author: sunwei
 * Date: 2025/3/17 08:57
 * Description:
 */
@EnableScheduling
@Configuration
@EnableConfigurationProperties
@MapperScan(value = {"com.holdtime.jtt809dataservice.business.hd.entity.mapper",
    "com.holdtime.jtt809.taxi.module.entity.mapper"})
@SpringBootApplication(scanBasePackages = {"com.holdtime.jtt809dataservice",
    "com.holdtime.jtt809.taxi"})
public class JTT809DataServiceApplication {
    @Value("${btjjxyt.parentPlatformIp}")
    private String parentPlatformIp;
    @Value("${btjjxyt.parentPlatformPort}")
    private int parentPlatformPort;

    @Autowired
    private SubordinatePlatformClientHandler subordinatePlatformClientHandler;
    public static void main(String[] args) {
        SpringApplication.run(JTT809DataServiceApplication.class, args);
    }

    @Bean
    // 定义一个名为protocolJT809的Bean
    public ProtocolJT809 protocolJT809() {
        // 返回一个ProtocolJT809对象，参数分别为：协议头，主链路心跳周期，从链路心跳周期，链路超时时间
        return new ProtocolJT809(new byte[]{0, 0, 1}, 12345, 23456, 34567);
    }

    @Bean
    public TcpClient subordinatePlatformClient() {
        return new TcpClient(
                subordinatePlatformClientHandler,
                parentPlatformIp,
                parentPlatformPort
        );
    }
}
